//
//  TransitionController.m
//  CAAnimation
//
//  Created by 周文成 on 2017/12/13.
//  Copyright © 2017年 C-LOVE. All rights reserved.
//

#import "TransitionController.h"
#import "CATransitionType.h"

@interface TransitionController () {
    NSArray  *_dictionaryTypes;
    NSString *_imageName;
    
}

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *tipsLabel;

@property (nonatomic, assign) NSInteger dictionnaryIndex;

@property (nonatomic, strong) CATransition *animation;

@end

@implementation TransitionController

+ (instancetype)transitionController {
    TransitionController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"TransitionController"];
    return controller;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _dictionaryTypes = @[kCATransitionFromTop, kCATransitionFromBottom, kCATransitionFromLeft, kCATransitionFromRight];
    _imageName = @"wolf";
    
    self.dictionnaryIndex = 0;
    self.animation.duration = 1;
    
    self.tipsLabel.text = @"Top";
}


- (void)setIndex:(NSInteger)index {
    _index = index;
    switch (self.index) {
        case 0:
            self.animation.type = TYPE_FADE;
            break;
        case 1:
            self.animation.type = TYPE_PUSH;
            break;
        case 2:
            self.animation.type = TYPE_MOVE_IN;
            break;
        case 3:
            self.animation.type = TYPE_REVEAL;
            break;
        case 4:
            self.animation.type = TYPE_CUBE;
            break;
        case 5:
            self.animation.type = TYPE_OGL_FLIP;
            break;
        case 6:
            self.animation.type = TYPE_SUCK_EFFECT;
            break;
        case 7:
            self.animation.type = TYPE_RIPPLE_EFFECT;
            break;
        case 8:
            self.animation.type = TYPE_PAGECURL;
            break;
        case 9:
            self.animation.type = TYPE_CAMERA_OPEN;
            break;
        case 10:
            self.animation.type = TYPE_CAMERA_CLOSE;
            break;
            
        default:
            break;
    }
}

- (void)setDictionnaryIndex:(NSInteger)dictionnaryIndex {
    if(dictionnaryIndex >= 4){
        _dictionnaryIndex = 0;
    }
    else {
        _dictionnaryIndex = dictionnaryIndex;
    }
}


- (void)changeImage {
    
    switch (self.dictionnaryIndex) {
        case 0:{
            self.tipsLabel.text = @"Top";
        }
            break;
        case 1:{
            self.tipsLabel.text = @"Bottom";
        }
            break;
        case 2:{
            self.tipsLabel.text = @"Left";
        }
            break;
        case 3:{
            self.tipsLabel.text = @"Right";
        }
            break;
            
        default:
            break;
    }
    self.dictionnaryIndex ++;
    self.animation.subtype = [_dictionaryTypes objectAtIndex:self.dictionnaryIndex];
    
    NSString *imageName = [_imageName isEqualToString:@"grass"]? @"wolf":@"grass";
    self.imageView.image = [UIImage imageNamed:imageName];
    _imageName = imageName;
    [self.imageView.layer addAnimation:_animation forKey:@"TransitionAnimation"];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    
    [self changeImage];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
